package com.xdap.keymen.service.dayang;

import com.definesys.mpaas.query.MpaasQuery;
import com.xdap.keymen.entity.dayang.DaYangShopMapEntity;
import com.xdap.runtime.service.RuntimeAppContextService;
import com.xdap.runtime.service.RuntimeDatasourceService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class DaYangShopMapService extends BaseService{
    private final RuntimeDatasourceService runtimeDatasourceService;
    private final RuntimeAppContextService runtimeAppContextService;
    public DaYangShopMapEntity getShopMap(DaYangShopMapEntity entity) {
        String currentTenantId = runtimeAppContextService.getCurrentTenantId();
        MpaasQuery query = runtimeDatasourceService.buildTenantMpaasQuery("xdap_app_" + currentTenantId);
        query.eq("shop_douyin", entity.getShopDouyin());
        query.eq("shop_weimo", entity.getShopWeimo());
        query.eq("shop_dayang", entity.getShopDayang());
        query.eq("shop_defan", entity.getShopDefan());
        return query.doQueryFirst(DaYangShopMapEntity.class);
    }

    public List<DaYangShopMapEntity> getAll(){
        String currentTenantId = runtimeAppContextService.getCurrentTenantId();
        MpaasQuery query = runtimeDatasourceService.buildTenantMpaasQuery("xdap_app_" + currentTenantId);
        return query.doQuery(DaYangShopMapEntity.class);
    }
}
